package com.ppch.zerocodegenerator.exception;

/**
 * Package:ppch.zerocodegenerator
 * ClassName:ThrowUtils
 *
 * @Author 泡泡茶壶
 * @Create 2024/12/13 21:00
 * @Version 1.0
 * Description:
 * 自定义断言类，可以更方便的进行条件判断
 */
public class ThrowUtils {

    /**
     * 断言：条件成立则抛出异常
     * @param condition 判断条件
     * @param runtimeException 要抛出的异常
     */
    public static void throwIf(boolean condition,RuntimeException runtimeException){
        if(condition){
            throw runtimeException;
        }
    }

    /**
     * 断言：条件成立则抛出异常
     * @param condition 判断条件
     * @param errorCode 错误状态码
     */
    public static void throwIf(boolean condition,ErrorCode errorCode){
       throwIf(condition,new BusinessException(errorCode));
    }

    /**
     * 断言：条件成立则抛出异常
     * @param condition 判断条件
     * @param errorCode 错误状态码
     * @param message 详细错误信息
     */
    public static void throwIf(boolean condition,ErrorCode errorCode,String message){
        throwIf(condition,new BusinessException(errorCode,message));
    }
}
